package com.zys.el.user.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zys.el.core.service.impl.CrudServiceImpl;
import com.zys.el.user.dao.ProssionDao;
import com.zys.el.user.po.Prossion;
import com.zys.el.user.service.IProssionService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ProssionServiceImpl extends CrudServiceImpl<Prossion> implements IProssionService {
    /**
     * 根据用户id得到用户所在市的所有高校对应的专业列表id
     *
     * @param userId
     * @return
     */
    @Override
    public Map<String, List<Long>> getSchoolNameByUserId(Long userId) {
        List<String> schools = ((ProssionDao) getBaseMapper()).getSchoolNameByUserId(userId)
                .stream().map(Prossion::getSchool).collect(Collectors.toList());
        Map<String, List<Long>> schoolFaceProfessionListId = new HashMap<>();
        for (String school : schools) {
            List<Long> schoolFaceProfessionList = this.baseMapper.selectList(new QueryWrapper<Prossion>().eq("school", school))
                    .stream().map(Prossion::getId).collect(Collectors.toList());
            schoolFaceProfessionListId.put(school, schoolFaceProfessionList);
        }
        return schoolFaceProfessionListId;
    }

    /**
     * 通过用户id得到用户专业信息
     *
     * @param userId
     * @return
     */
    public Prossion getSchoolOneNameByUserId(Long userId) {
        return ((ProssionDao) this.baseMapper).getSchoolOneNameByUserId(userId);
    }

    /**
     * 通过目标id得到目标的用户所在的省份
     *
     * @param targetId
     * @return
     */
    public Prossion getProfessionByTargetId(Long targetId) {
        return ((ProssionDao) this.baseMapper).getProfessionByTargetId(targetId);
    }

    /**
     * 获取所有省份
     *
     * @return
     */
    @Override
    public List<String> getProvinceList() {
        return ((ProssionDao) this.baseMapper).getProvinceList()
                .stream().map(Prossion::getProvince)
                .collect(Collectors.toList());
    }

    /**
     * 通过省份名称获取所有城市
     *
     * @param provinceName
     * @return
     */
    @Override
    public List<String> getCityByProvinceName(String provinceName) {
        return ((ProssionDao) this.baseMapper)
                .getCityByProvinceName(provinceName)
                .stream().map(Prossion::getCity)
                .collect(Collectors.toList());

    }

    /**
     * 通过城市名称获取所有学校
     *
     * @param cityName
     * @return
     */
    @Override
    public List<String> getSchoolByCityName(String cityName) {
        return ((ProssionDao) this.baseMapper)
                .getSchoolByCityName(cityName)
                .stream().map(Prossion::getSchool)
                .collect(Collectors.toList());
    }

    /**
     * 通过学校名称获取所有院
     *
     * @param schoolName
     * @return
     */
    @Override
    public List<String> getProfessionTypeBySchoolName(String schoolName) {
        return ((ProssionDao) this.baseMapper)
                .getProfessionTypeBySchoolName(schoolName)
                .stream().map(Prossion::getProssionType)
                .collect(Collectors.toList());
    }

    /**
     * 通过院名称和学校名称获取所有专业
     *
     * @param professionType
     * @param schoolName
     * @return
     */
    @Override
    public List<String> getProfessionByTypeAndSchoolName(String professionType, String schoolName) {
        return ((ProssionDao) this.baseMapper)
                .getProfessionByTypeAndSchoolName(professionType, schoolName)
                .stream().map(Prossion::getProssionName)
                .collect(Collectors.toList());
    }
}
